package org.example.pd.service.Impl;

import org.example.pd.domain.*;
import org.example.pd.mapper.PdMapper;
import org.example.pd.service.MajorSourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MajorSourceServiceImpl implements MajorSourceService {

    @Autowired
    PdMapper pdMapper;

    //    归一化方法
    @Override
    public double normalization(double score, double maxNum, double minNum) {
        return (score - minNum) / (maxNum - minNum);
    }

    @Override
    public double[] getMaxMin(List<Object> obj) {
//        for (Object object:obj){
//            object.
//        }
//        return new double[0];

        return null;
    }

    @Override
    public List<String> getMajorName(String year, String category) {
        return pdMapper.getMajorName(year, category);
    }

    @Override
    public List<String> getSchool(String year, String majorName) {
        return pdMapper.getSchool(year, majorName);
    }



    @Override
    public List<FirstVolunteer> getFirstVolunteer(String year, List<String> schoolCode, String majorName) {
        List<FirstVolunteer> firstVolunteers = pdMapper.getFirstVolunteer(year, schoolCode, majorName);
//        Normalizer.normalizeEntities(firstVolunteers);
        return firstVolunteers;
    }

    @Override
    public List<FirstVolunteer> getAdmissionRate(String year, List<String> schoolCode, String majorName) {
        List<FirstVolunteer> admissionRates = pdMapper.getAdmissionRate(year, schoolCode, majorName);
//        Normalizer.normalizeEntities(admissionRates);
        return admissionRates;
    }

    // 录取分数(归一化处理)
    @Override
    public List<AdmissionScore> getAdmissionScore(String year, List<String> schoolCode, String majorName) {
        List<AdmissionScore> admissionScores = pdMapper.getAdmissionScore(year, schoolCode, majorName);
//        Normalizer.normalizeEntities(admissionScores);
        return admissionScores;
    }

    // 优势专业
    @Override
    public List<AdvantageousMajors> getAdvantageousMajors( String year, List<String> schoolCode, String majorName) {
        return pdMapper.getAdvantageousMajors(year, schoolCode, majorName);
    }

    // 高层次称号
    @Override
    public  List<HighLevelTitle> getHighLevelTitle(String year, List<String> schoolCode, String majorName) {
        return pdMapper.getHighLevelTitle(year, schoolCode, majorName);
    }

    @Override
    public List<HighLevelTeam> getHighLevelTeam(String year, List<String> schoolCode, String majorName) {
        return pdMapper.getHighLevelTeam(year, schoolCode, majorName);
    }

    // 转专业
    @Override
    public List<TransferMajor> transferMajor(String year, List<String> schoolCode, String majorName) {
        List<TransferMajor> transferMajors = pdMapper.getTransferMajor(year, schoolCode, majorName);
        return transferMajors;
    }

//     专任教师数量及结构
    @Override
    public List<FullTimeTeachers> numberStructure(String year, List<String> schoolCode, String majorName){
        return pdMapper.getFullTimeTeachers(year, schoolCode, majorName);
    }

    // 专业教师承担教学情况
    @Override
    public List<FullTimeTeachersTeach> getFullTimeTeachersTeach(String year, List<String> schoolCode, String majorName) {
        return pdMapper.getFullTimeTeachersTeach(year, schoolCode, majorName);
    }

    //培训进修情况
    @Override
    public List<TeacherTraining> getTraining(String year, List<String> schoolCode, String majorName) {
        return pdMapper.getTeacherTraining(year, schoolCode, majorName);
    }

    @Override
    public List<EduResearchReform> getEduResearchReform(String year, List<String> schoolCode, String majorName) {
        List<EduResearchReform> eduResearchReforms = pdMapper.getEduResearchReform(year, schoolCode, majorName);
        return eduResearchReforms;
    }

    // 教学成果奖
    @Override
    public List<TeachingAward> getTeachingAward(String year, List<String> schoolCode, String majorName) {
        return pdMapper.getTeachingAward(year, schoolCode, majorName);
    }

    // 主持科研项目
    @Override
    public List<LeadResearchProjects> getLeadResearchProjects(String year, List<String> schoolCode, String majorName) {
        return pdMapper.getLeadResearchProjects(year, schoolCode, majorName);
    }

    // 发表论文情况
    @Override
    public List<PublishPaper> getPublishPaper(String year, List<String> schoolCode, String majorName) {
        List<PublishPaper> publishPapers = pdMapper.getPublishPaper(year, schoolCode, majorName);
        return publishPapers;
    }

    //专利专著
    @Override
    public List<PatentMonograph> getPatentMonograph(String year, List<String> schoolCode, String majorName) {
        List<PatentMonograph> patentMonographs = pdMapper.getPatentMonograph(year, schoolCode, majorName);
        return patentMonographs;
    }

    //科研成果转化情况
    @Override
    public  List<ResTransferStatus> getResTransferStatus(String year, List<String> schoolCode, String majorName) {
        return pdMapper.getResTransferStatus(year, schoolCode, majorName);
    }
    /**
     * 根据学校名称计算各学校科研成果转化情况总分。
     *
     * @param resTransferStatuses 包含科研转化情况的列表
     * @return 各学校及其总分的映射
     */
    public static Map<String, Double> calculateTotalScoresBySchool(List<ResTransferStatus> resTransferStatuses) {
        Map<String, Double> totalScores = new HashMap<>();
        for (ResTransferStatus conversion : resTransferStatuses) {
            String schoolName = conversion.getSchoolName();
            double score = conversion.getScore();
            // 如果 map 中已经存在该学校，则累加分数；否则，初始化为当前分数
            totalScores.merge(schoolName, score, Double::sum);
        }
        return totalScores;
    }

    //专业实验教学校内场所情况
    @Override
    public List<LaboratoryCampus> getLaboratoryCampus(String year, List<String> schoolCode, String majorName) {
        return pdMapper.getLaboratoryCampus(year, schoolCode, majorName);
    }

    @Override
    public List<ProvincialProjectBase> getProvincialProjectBase(String year, List<String> schoolCode, String majorName) {
        return pdMapper.getProvincialProjectBase(year, schoolCode, majorName);
    }

    @Override
    public List<PracticalBaseStatus> getPracticalBaseStatus(String year, List<String> schoolCode, String majorName) {
        return pdMapper.getPracticalBaseStatus(year, schoolCode, majorName);
    }

    @Override
    public List<Textbook> getTextbook(String year, List<String> schoolCode, String majorName) {
        return pdMapper.getTextbook(year, schoolCode, majorName);
    }

    @Override
    public List<InfoCourseBuild> getInfoCourseBuild(String tabelName, String year, List<String> schoolCode, String majorName) {
        return pdMapper.getInfoCourseBuild(tabelName, year, schoolCode, majorName);
    }


    // 参加创新创业训练计划
    @Override
    public List<InnovationParticipation> getInnovationParticipation(String year, List<String> schoolCode, String majorName) {
        return pdMapper.getInnovationParticipation(year, schoolCode, majorName);
    }
    // 参加教师科研情况
    @Override
    public List<TeacherResPartic> getTeacherResPartic(String year, List<String> schoolCode, String majorName) {
        return pdMapper.getTeacherResPartic(year, schoolCode, majorName);
    }
    // 学生交流情况
    @Override
    public List<UndergradExchange> getUndergradExchange(String year, List<String> schoolCode, String majorName) {
        return pdMapper.getUndergradExchange(year, schoolCode, majorName);
    }
    // 学习成效
    @Override
    public List<LearnResult> getLearnResult(String year, List<String> schoolCode, String majorName) {
        return pdMapper.getLearnResult(year, schoolCode, majorName);
    }

    // 毕业综合训练情况
    @Override
    public List<GradCompTraining> getGradCompTraining(String year, List<String> schoolCode, String majorName) {
        return pdMapper.getGradCompTraining(year, schoolCode, majorName);
    }

    // 教师指导学生毕业综合训练情况=学生与指导教师比。
    @Override
    public List<EmploymentNumber> graduateTrainTeacher(String year, List<String> schoolCode, String majorName) {
        return pdMapper.getTrainingStudent(year, schoolCode, majorName);
    }

    @Override
    public List<EmploymentNumber> graduateTrainStu(String year, List<String> schoolCode, String majorName) {
        return pdMapper.getTrainingTeacher(year, schoolCode, majorName);
    }

    // 就业率-就业学生数量
    public List<EmploymentNumber> employmentNumbers(String year, List<String> schoolCode, String majorName){
        return pdMapper.getEmploymentNumber(year, schoolCode, majorName);
    }
    // 就业率-毕业学生数量
    public List<EmploymentNumber> getGraduateNumbers(String year, List<String> schoolCode, String majorName){
        return pdMapper.getGraduateNumber(year, schoolCode, majorName);
    }
    // 考研率
    @Override
    public List<EmploymentNumber> getHigherSchoolNumber(String year, List<String> schoolCode, String majorName){
        return pdMapper.getHigherSchoolNumber(year, schoolCode, majorName);
    }

    // 就业去向-省内比例
    @Override
    public List<EmploymentDestinations> employmentDestinations(String year, List<String> schoolCode, String majorName) {
        return pdMapper.getEmploymentDestinations(year, schoolCode, majorName);
    }

    //一流课程建设
    @Override
    public List<TopCourse> getTopCourse(String year, List<String> schoolCode, String majorName) {
        return pdMapper.getTopCourse(year, schoolCode, majorName);
    }

    @Override
    public List<String> geySchoolNameByCode(List<String> schoolCode,String year) {
        return pdMapper.geySchoolNameByCode(schoolCode,year);
    }


}
